<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extra/spring-security">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-cale=1, shrink-to-fit=no">
    <link rel="icon" type="shortcut icon" th:href="@{/static/img/favicon.ico}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/global.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/discuss-detail.css}"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
    <link rel="stylesheet" type="text/css" th:href="@{/static/editor-md/css/editormd.css}"/>
    <script th:src="@{/static/js/jquery-3.1.0.min.js}"></script>
    <base th:href="${#servletContext.getContextPath()+'/'}">
    <title>Echo - 帖子详情</title>
    <script type="text/javascript">
        function userHeaderError(id,dom) {
            let filePath = $(dom).attr("mypath");
            $("#user-header-"+id).attr("src","FileController/showPng?filePath=" + filePath);
        }
        function commentUserHeaderError(id, dom) {
            $("[id='commentUser-header-" + id +"']").each(function(){
                console.log(this);
                let filePath = $(dom).attr("mypath");
                $(this).attr("src", "FileController/showPng?filePath=" + filePath);
            });
        }
    </script>
</head>
<body>
<div class="nk-container">
    <!-- 头部 -->
    <header class="bg-dark sticky-top" th:replace="view\index::header"></header>

    <!-- 内容 -->
    <div class="main">
        <!-- 帖子详情 -->
        <div class="container">
            <!-- 标题 -->
            <h5 class="mb-4">
                <i class="bi bi-award" style="color: rgb(119, 84, 223)"></i>
                <span th:utext="${topic.title}"></span>
                <div class="float-right">
                    <!--						<input type="hidden" id="postId" th:value="${post.id}">-->
                    <!--						<input type="hidden" id="postType" th:value="${post.type}">-->
                    <!--						<button type="button" th:class="|btn ${post.type == 0 ? 'btn-danger' : 'btn-info'}  btn-sm|" id="topBtn"-->
                    <!--						 		th:text="${post.type == 0 ? '置顶' : '取消置顶'}"-->
                    <!--								sec:authorize="hasAnyAuthority('moderator')">-->
                    <!--						</button>-->
                    <!--						<button type="button" class="btn btn-danger btn-sm" id="wonderfulBtn"-->
                    <!--								th:disabled="${post.status == 1}" sec:authorize="hasAnyAuthority('moderator')">加精</button>-->
                    <!--						<button type="button" class="btn btn-danger btn-sm" id="deleteBtn"-->
                    <!--								th:disabled="${post.status == 2}" sec:authorize="hasAnyAuthority('admin')">删除</button>-->
                </div>
            </h5>
            <!-- 作者 -->
            <div class="media pb-3 border-bottom">
                <a th:href="@{|/UserController/info/${user.id}|}">
                    <img th:id="|user-header-${user.id}|"
                         th:onerror="|userHeaderError(${user.id},this)|"
                         th:src="${user.headerUrl}"
                         th:attr="mypath=${user.headerUrl}"
                         class="align-self-start mr-4 rounded-circle user-header" alt="用户头像">
                </a>
                <div class="media-body">
                    <div class="mt-0 text-warning" th:utext="${user.username}"></div>
                    <div class="text-muted mt-3">
                        发布于 <b th:text="${#dates.format(topic.createTime, 'yyyy-MM-dd HH:mm:ss')}"></b>
                        <ul class="d-inline float-right">
                            <li class="d-inline ml-2">
                                <a href="javascript:;"
                                   th:onclick="|like(this, 1, ${topic.id}, ${user.id}, ${topic.id});|"
                                   class="text-primary">
                                    <b th:text="${likeStatus == 1 ? '已赞' : '赞'}"></b>
                                    <i th:text="${likeCount}"></i>
                                </a>
                            </li>
                            <li class="d-inline ml-2">|</li>
                            <li class="d-inline ml-2"><a href="#replyform" class="text-primary">回帖 <i>0</i></a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <!-- 正文 -->
            <div class="mt-4 mb-3 content" id="md-content">
                <textarea style="display:none;" th:utext="${topic.content}"></textarea>
            </div>

            <!--<div class="mt-4 mb-3 content" id = "md-content" ></div>-->
        </div>
        <!-- 回帖 -->
        <div class="container mt-3">
            <!-- 回帖数量 -->
            <div class="row">
                <div class="col-8">
                    <h6><b class="square"></b> <i th:text="${commentVoList.size()}"></i>条回帖</h6>
                </div>
                <div class="col-4 text-right">
                    <a href="#replyform" class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;帖&nbsp;&nbsp;</a>
                </div>
            </div>
            <!-- 回帖列表 -->
            <ul class="list-unstyled mt-4">
                <li class="media pb-3 pt-3 mb-3 border-bottom" th:each="commVo:${commentVoList}">
                    <a th:href="@{|/UserController/info/${commVo.userEntity.id}|}">
                        <img th:id="|commentUser-header-${commVo.userEntity.id}|"
                             th:onerror="|commentUserHeaderError(${commVo.userEntity.id},this)|"
                             th:src="${commVo.userEntity.headerUrl}"
                             th:attr="mypath=${commVo.userEntity.headerUrl}"
                             class="align-self-start mr-4 rounded-circle user-header" alt="用户头像">
                    </a>
                    <div class="media-body">
                        <div class="mt-0">
                            <span class="font-size-12 text-success" th:utext="${commVo.userEntity.username}"></span>
                            <span class="badge badge-secondary float-right floor">
        									<!-- 楼数 -->
                                <!--        									<i th:text="${page.offset + cvoStat.count}"></i> 楼-->
        								</span>
                        </div>
                        <div class="mt-2" th:utext="${commVo.comment2Vo.content}"></div>
                        <div class="mt-4 text-muted font-size-12">
                            <span>发布于 <b
                                    th:utext="${commVo.comment2Vo.createTimeText}"></b></span>
                            <ul class="d-inline float-right">
                                <li class="d-inline ml-2">
                                    <a href="javascript:;"
                                       th:onclick="|like(this, 2, ${commVo.comment2Vo.id}, ${commVo.userEntity.id}, ${commVo.userEntity.id});|"
                                       class="text-primary">
                                        <b th:text="${commVo.likeStatus == 1 ? '已赞' : '赞'}"></b>
                                        (<i th:text="${commVo.likeCount}">0</i>)
                                    </a>
                                </li>
                                <li class="d-inline ml-2">|</li>
                                <li class="d-inline ml-2">
                                    <a href="#" class="text-primary">回复(<i>0</i>)</a>
                                </li>
                            </ul>
                        </div>
                        <!-- 回复列表 -->
                        <ul class="list-unstyled mt-4 bg-gray p-3 font-size-12 text-muted">
                            <li class="pb-3 pt-3 mb-3 border-bottom" th:each="reply:${commVo.replyList}">
                                <div>
                                    <!--        										<span th:if="${rvo.target==null}">-->
                                    <!--        											<a class="text-info" th:utext="${rvo.user.username}" th:href="@{|/user/profile/${rvo.user.id}|}"></a>:&nbsp;&nbsp;-->
                                    <!--        										</span>-->
                                    <span th:if="${reply !=null}">
        											<a class="text-info" th:text="${reply.userEntity.username}" th:href="@{|/account/info/${reply.userEntity.id}|}">
													</a> 回复
        											<a class="text-info" th:utext="${reply.targetEntity.username}"
                                                       th:href="@{|/account/info/${reply.comment2Vo.targetId}|}">
													</a>:&nbsp;&nbsp;
        										</span>
                                    <span th:text="${reply.comment2Vo.content}"></span>
                                </div>
                                <div class="mt-3">
                                    <span th:utext="${reply.comment2Vo.createTimeText}"></span>
                                    <ul class="d-inline float-right">
                                        <li class="d-inline ml-2">
                                            <a href="javascript:;"  th:onclick="|like(this,2,${reply.comment2Vo.id},${reply.userEntity.id})|" class="text-primary">
                                                <b th:text="${reply.likeStatus == 1 ? '已赞' : '赞'}"></b>
                                                (<i th:text="${reply.likeCount}"></i>)
                                            </a>
                                        </li>
                                        <li class="d-inline ml-2">|</li>
                                        <li class="d-inline ml-2"><a th:href="|#huifu-${reply.comment2Vo.id}|" data-toggle="collapse" class="text-primary">回复</a></li>
                                    </ul>
                                    <div th:id="|huifu-${reply.comment2Vo.id}|" class="mt-4 collapse">
                                        <form method="post" th:action="@{|/CommentController/add/${topic.id}|}">
                                            <div>
                                                <input type="text" class="input-size" name="content" th:placeholder="|回复${reply.userEntity.username}|"/>
                                                <!-- 这里是回复给评论的所以写死2-->
                                                <input type="hidden" name="entityType" value="2">
                                                <!-- 评论的ID-->
                                                <input type="hidden" name="entityId" th:value="${commVo.comment2Vo.id}">

                                                <!-- 评论的作者id-->
                                                <input type="hidden" name="targetId" th:value="${reply.userEntity.id}">
                                            </div>
                                            <div class="text-right mt-2">
                                                <button type="submit" class="btn btn-primary btn-sm" >&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </li>

                            <!-- 回复输入框 -->
                            <li class="pb-3 pt-3">
                                <form method="post" th:action="@{|/CommentController/add/${topic.id}|}">
                                    <div>
                                        <input type="text" class="input-size" name = "content" placeholder="请输入你的观点"/>
                                        <!-- 2代表是给人评论 -->
                                        <input type="hidden" name="entityType" value="2">
                                        <input type="hidden" name="entityId" th:value="${commVo.comment2Vo.id}"> <!-- 被评论的ID-->
                                        <input type="hidden" name="targetId" th:value="${commVo.userEntity.id}"> <!-- 被评论人的ID-->

                                    </div>
                                    <div class="text-right mt-2">
                                        <button type="submit" class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
                                    </div>
                                </form>
                            </li>
                        </ul>
                    </div>
                </li>

            </ul>

        </div>
        <!--			 回帖输入 -->
        <div class="container mt-3">
            <form class="replyform" method="post" id="reply-form" th:action="@{|/CommentController/add/${topic.id}|}">
                <p class="mt-3">
                    <a name="replyform"></a>
                    <textarea placeholder="在这里畅所欲言你的看法吧!" name="content"></textarea>
<!--                    代表当前评论给帖子-->
                    <input type="hidden" name="entityType" value="1">
<!--                    设置帖子的id-->
                    <input type="hidden" name="entityId" th:value="${topic.id}">
<!--                    设置帖子的作者-->
                    <input type="hidden" name="targetId" th:value="${user.id}">
                </p>
                <p class="text-right">
                    <button type="submit" class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;帖&nbsp;&nbsp;</button>
                </p>
            </form>
        </div>
    </div>

    <!-- 尾部 -->
    <footer class="bg-dark" th:replace="view\index::footer"></footer>

</div>
<script th:src="@{/static/js/popper.min.js}"></script>
<script th:src="@{/static/js/bootstrap.min.js}"></script>
<script th:src="@{/static/js/global.js}"></script>
<script th:src="@{/jquery/http.js}"></script>
<script th:src="@{/static/js/discuss.js}"></script>
<script th:src="@{/static/editor-md/lib/marked.min.js}"></script>
<script th:src="@{/static/editor-md/lib/prettify.min.js}"></script>
<script th:src="@{/static/editor-md/lib/raphael.min.js}"></script>
<script th:src="@{/static/editor-md/lib/underscore.min.js}"></script>
<script th:src="@{/static/editor-md/lib/sequence-diagram.min.js}"></script>
<script th:src="@{/static/editor-md/lib/flowchart.min.js}"></script>
<script th:src="@{/static/editor-md/lib/jquery.flowchart.min.js}"></script>
<script th:src="@{/static/editor-md/editormd.min.js}"></script>
<script type="text/javascript">
    var testEditor;
    $(function () {
        testEditor = editormd.markdownToHTML("md-content", {
            htmlDecode: "style,script,iframe",
            emoji: true,
            taskList: true,
            tex: true, // 默认不解析
            flowChart: true, // 默认不解析
            sequenceDiagram: true, // 默认不解析
            codeFold: true
        })
    })

    // $(function () {
    //     $("#reply-form").submit(function () {
    //         console.log("点击回帖")
    //         submit("reply-form", "CommentController/add", function (data) {
    //             console.log("是否响应成功");
    //             if (data.code === 200) {
    //                 location.reload();
    //             }else {
    //                 console.log("响应失败");
    //                 let con = window.confirm("请先登录,点击确定将会跳转到登录页面");
    //                 if(con){
    //                     location.href="view/site/login.html";
    //                 }
    //
    //             }
    //         });
    //         return false;
    //     });
    // })
</script>

</body>
</html>
